%clear

%Plotting for different format of region 17
scrsz = get(groot,'ScreenSize');
load ../collect_all.mat
load ../data/compile_zones_JF.mat %load JF data
plj=find(All.region==17);

ctr=17;
R=region_data_all(ctr);
fname=['../data/data_',R.name,'.mat'];
load(fname,'C');    
H=figure('position',[500,500,1000,450]); hold on;

%identify transects
tr=All.transect;
plt=find(tr(:,1)==ctr);
lines=unique(tr(plt,2));

offset=3*nanstd(C.T(lines(1)).z);
offset=round(offset/10)*10; 

%plot transects
for ct=1:length(lines),
    [~,plbm]=min(abs(C.T(lines(ct)).t-(-780)));
    z=-smoothPH(C.T(lines(ct)).z,11);
    dist=C.T(lines(ct)).dist;
    pl=find(isnan(z)==0 & isnan(dist)==0); 
    z=z(pl);
    dist=dist(pl);
    mz=interp1(dist,z,0,'linear','extrap');
    plot(dist,z-mz+offset*ct,'k','linewidth',1);
    plot(0,offset*ct,'ro','markersize',12,'linewidth',2); 
    plot(C.T(lines(ct)).dist(plbm),z(plbm)-mz+offset*ct,'ro','markersize',6,'markerfacecolor','r');
    try,
        distbm=P.T(lines(ct)).BM(1).idist; %location of the B-M magnetic reversal on one side
        plot(distbm,interp1(dist,z-mz+offset*ct,distbm),'r.','markersize',22);
    end;
    try,
        distbm=P.T(lines(ct)).BM(2).idist; %location of the B-M magnetic reversal on one side
        plot(distbm,interp1(dist,z-mz+offset*ct,distbm),'r.','markersize',22);
    end;
end;
axis tight; h4=axis;
for ct=1:length(lines);
    text(h4(2),offset*ct,num2str(lines(ct),2),'fontsize',15,'linewidth',1);
end;

%name
axis([h4(1)-diff(h4(1:2))*0.05 h4(2:4)]); h4=axis;
plot([0 0],h4(3:4),'k--','linewidth',1);
%text(h4(1),h4(4)-0.05*diff(h4(3:4)),R.name,'fontsize',18); 
text(h4(1),h4(4)-0.05*diff(h4(3:4)),'bathymetry','fontsize',18); 
axis off;

%unit bar
dx=diff(h4(1:2));
dy=diff(h4(3:4));
x=[1 1]*h4(1)+0.001*dx;
y=[h4(4)-0.15*dy h4(4)-0.15*dy-offset];
plot(x,y,'k','linewidth',1.5);
if dy>8*offset;
    label=round(linspace(0,offset,2));
end;
if dy<=8*offset & dy>4*offset;
    label=round(linspace(0,offset,3));
end;
if dy<=4*offset;
    label=round(linspace(0,offset,5));
end;

%transect number labels
for ct=1:length(label);
    plot([x(1) x(1)+0.005*dx],y(2)*[1 1]+label(ct),'k','linewidth',1.5);
    text(x(1)+0.01*dx,y(2)+label(ct),[num2str(label(ct)),' m'],'linewidth',1.5,'fontsize',12);
end;

%make x-axis
subplot('position',[0.05 0.098 0.85 0.001]); 
axis([h4(1:2) 0 1]);
font(gca,15);
h=xlabel('distance (km)'); font(h,15);
